<?php

namespace Common\Model;
use Think\Model;
class User_answerModel extends Model {

    /**
     * 获得测试的问卷名称，进度信息
     * @param $quiz_list
     * @param $uid
     * @return array
     */
    public function QuizDetail($quiz_list, $uid){

        $i = 0;
        $rs = [];
        foreach($quiz_list as $quiz_name){
            $count = $this->join("quiz_info on quiz_info.quiz_id = user_answer.quiz_id  ")
                ->where(["user_id" => $uid, "quiz_name" => $quiz_name])->count();

            $question_num = M('question')->join("quiz_info on quiz_info.quiz_id = question.quiz_id")->where(['quiz_info.quiz_name' => $quiz_name])->count();
            $rs[$i]['percent'] = ($count/$question_num)*100;
            $quiz_info = M('quiz_info')->where(['quiz_name' => $quiz_name])->select();
            $quiz_title = $quiz_info[0]['quiz_pagetitle'];
            $rs[$i]['quiz_id'] = $quiz_info[0]['quiz_id'];
            $rs[$i]['quiz_title'] = $quiz_title;
            $i++;
        }
        return $rs;
    }

}